﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;

using ZhimeiSoft.CharmManager.DOL;
using ZhimeiSoft.CharmManager.Server.DAL.Interface;
using ZhimeiSoft.Framework.Server.Base;

namespace ZhimeiSoft.CharmManager.Server.DAL
{
    public class CustomerPaymentDAL: BaseDal, ICustomerPaymentDAL
    {
        private void AddInSqlParameters(ref DbCommand cmd, DBEntityCustomerPayment entity)
        {
            if (entity == null || cmd == null)
                return;

            DB.AddInParameter(cmd, DBEntityCustomerPayment.FieldName.CPAYDATE, DbType.DateTime, entity.CPayDate);
            DB.AddInParameter(cmd, DBEntityCustomerPayment.FieldName.CEMPLOYEEID, DbType.Int32, entity.CEmployeeID);
            DB.AddInParameter(cmd, DBEntityCustomerPayment.FieldName.CMEMO, DbType.String, entity.CMemo);
            DB.AddInParameter(cmd, DBEntityCustomerPayment.FieldName.CUSTOMERSERVICEITEMID, DbType.Int32, entity.CustomerServiceItemID);
            DB.AddInParameter(cmd, DBEntityCustomerPayment.FieldName.PAYTYPEID, DbType.Int32, entity.PayTypeID);
            DB.AddInParameter(cmd, DBEntityCustomerPayment.FieldName.CMONEY, DbType.Decimal, entity.CMoney);
        }
        #region ICustomerPaymentDAL 成员

        public DataSet GetCustomerPayment(string sFilter)
        {
            string strSQL = CustomerPaymentDAL_Const.SQL_SELECT_CUSTOMERPAYMENT;
            if (!string.IsNullOrEmpty(sFilter))
                strSQL = strSQL + " WHERE " + sFilter;
            DbCommand cmd = DB.GetSqlStringCommand(strSQL);
            return DB.ExecuteDataSet(cmd);
        }

        public void InsertCustomerPayment(DBEntityCustomerPayment entity)
        {
            string strSQL = CustomerPaymentDAL_Const.SQL_INSERT_CUSTOMERPAYMENT;
            DbCommand cmd = DB.GetSqlStringCommand(strSQL);
            this.AddInSqlParameters(ref cmd, entity);
            DB.ExecuteNonQuery(cmd);
        }

        public void UpdateCustomerPayment(DBEntityCustomerPayment entity)
        {
            string strSQL = CustomerPaymentDAL_Const.SQL_UPDATE_CUSTOMERPAYMENT;
            DbCommand cmd = DB.GetSqlStringCommand(strSQL);
            this.AddInSqlParameters(ref cmd, entity);
            DB.AddInParameter(cmd, DBEntityCustomerPayment.FieldName.CPAYMENTID, DbType.Int32, entity.CPaymentID);
            DB.ExecuteNonQuery(cmd);
        }

        public void DeleteCustomerPayment(int payment_id)
        {
            string strSQL = CustomerPaymentDAL_Const.SQL_DELETE_CUSTOMERPAYMENT;
            DbCommand cmd = DB.GetSqlStringCommand(strSQL);
            DB.AddInParameter(cmd, DBEntityCustomerPayment.FieldName.CPAYMENTID, DbType.Int32, payment_id);
            DB.ExecuteNonQuery(cmd);
        }

        #endregion
    }
}
